<?php

namespace App\Http\Controllers\Company;
use Illuminate\Http\Request;
use App\Models\Personal\ResumeRemark;
use App\Models\Company\CompanyJob;

class ResumeRemarkController extends CommonController
{
    /**
     * 简历备注保存
     * @param Request $request
     */
    public function resumeRemarkSave(Request $request){
        $user = auth()->guard('company')->user();
        if(!auth()->guard('company')->check()){
            return 1;
        }
        $resumeRemark = ResumeRemark::where('company_uid', $user->uid)->where('resume_id', $request->resume_id)->first();
        
        if(empty($resumeRemark)){ //新增记录
            $input = [
            'company_uid'=>$user->uid, 'resume_id'=>$request->resume_id, 'job_id'=>$request->job_id, 'record'=>$request->record, 'suitable'=>$request->suitable,  'content'=>$request->content, 'created_at'=>date('Y-m-d H:i:s'), 'updated_at'=>date('Y-m-d H:i:s')
            ];
            ResumeRemark::create($input);
        }else{ //修改记录
            $input = [
            'job_id'=>$request->job_id, 'record'=>$request->record, 'suitable'=>$request->suitable,  'content'=>$request->content, 'updated_at'=>date('Y-m-d H:i:s')
            ];
            ResumeRemark::where('id',$resumeRemark->id)->update($input);
        }
        $resumeRemark = ResumeRemark::where('company_uid', $user->uid)->where('resume_id', $request->resume_id)->first();
        $companyJob   = CompanyJob::where('id', $resumeRemark->job_id)->first(['job_title']);
        $resumeRemark->job_title = $companyJob->job_title;//应聘岗位

        //录用情况统计
        switch($resumeRemark->record){ 
            case 1:
                $resumeRemark->record = '未通知面试';
                break;
            case 2:
                $resumeRemark->record = '已通知面试';
                break;
            case 3:
                $resumeRemark->record = '已参加面试';
                break;
            case 4:
                $resumeRemark->record = '不录用';
                break;
            case 5:
                $resumeRemark->record = '决定录用';
                break;
            case 6:
                $resumeRemark->record = '已上班';
                break;
            case 7:
                $resumeRemark->record = '离职';
                break;
        }
        //人才合适度
        switch($resumeRemark->suitable){ 
            case 1:
                $resumeRemark->suitable = '不合适';
                break;
            case 2:
                $resumeRemark->suitable = '合适';
                break;
            case 3:
                $resumeRemark->suitable = '比较合适';
                break;
            case 4:
                $resumeRemark->suitable = '非常合适';
                break;
            case 5:
                $resumeRemark->suitable = '非常好但不合适';
                break;
        }
        return response()->json(['resumeRemark'=>$resumeRemark]);
    }
    
}
